# coding: utf-8
import sys
import json

sys.path.append("..")
from raft.node_launcher import StaticNodeLauncher

if __name__ == '__main__':
    # 将配置文件与参数中的信息转移到内存中
    print(sys.argv)
    with open('data/configure.json', 'r') as f:
        conf = json.load(f)
    conf['addr'] = tuple(conf['addr'])
    tuple_peers = dict()
    for x in conf['peers'].keys():
        tuple_peers[x] = (conf['peers'][x][0], conf['peers'][x][1])
    conf['peers'] = tuple_peers
    if len(sys.argv) == 5:
        conf['heartbeat_interval_ms'] = (float(sys.argv[1]), float(sys.argv[2]))
        conf['wait_ms'] = (float(sys.argv[3]), float(sys.argv[4]))
    else:
        conf['heartbeat_interval_ms'] = (10, 20)
        conf['wait_ms'] = (1500, 3000)
    conf['static_log_name'] = 'key.json'

    # 构造launcher对象
    launcher = StaticNodeLauncher(conf)

    # 开始node的工作
    launcher.launch()
